package ui;

import bean.User;
import service.UserService;
import service.impl.UserServiceImpl;
import utils.BusinessException;

/*用户登入*/
public class LoginClass extends BaseClass {
    private UserService userService;
    public LoginClass() {
        userService = ((UserService) beanFactory.getBean("userService"));
    }

    public void login() throws BusinessException {
        /*输入用户名和密码*/
        println(getString("input.username"));
        String username = input.nextLine();
        println(getString("input.password"));
        String password = input.nextLine();

        //匹配用户
        //UserService userService = new UserServiceImpl(); 已经用Bean工厂来配置对象了
        User user = userService.login(username, password);
        //判断查询的用户是否存在
        if (user != null) {
            currentUser = user;
        } else {
            throw new BusinessException("login.error");
        }
    }
}
